import type { AxiosResponse } from "axios"
import type { DefineComponent } from "vue"
import type { QueryDTO } from "./QueryDTO"

export interface TableCardType<V extends TableData> {
    name: string,
    searchBox?: SearchBox,
    buttons?: TableButton<any>[],
    columns?: SearchBoxColumn[],
    page?: TablePage,
    data: V[],
    displayCheckBox?: boolean,
    query?: (params: QueryDTO) => Promise<AxiosResponse<any, any>>
}

export interface DataGridResult<V extends TableData> {
    records: V[],
    total: number
}

export interface TablePage {
    // 当前第几页
    pageIndex?: number,
    // 每页可展示的条数选择框
    pageSizes?: number[],
    // 每页展示多少条
    pageSize?: number,
    // 布局
    layout?: string,
    total?: number
}

export interface TableData {
    id: string | null
}

export interface SearchBox {
    columns?: SearchBoxColumn[]
}

export interface SearchBoxColumn {
    id: string,
    name: string,
    value?: string | number | boolean,
    type?: SearchBoxColumnType,
    placeholder?: string,
    // 可选参数，当下拉选时赋值或者通过url赋值
    items?: SearchBoxItem[],
    url?: string,
    columns?: SearchBoxColumn[],
    width?: string
}

export enum SearchBoxColumnType {
    Text = 1,
    Selection = 2,
    Switch = 3
}

export interface SearchBoxItem {
    text: string,
    value: string | number
}

export interface TableButton<I extends DefineComponent> {
    name: string,
    type?: string,
    icon?: I,
    onclick?: (selections: any[]) => void
}

export interface TableSelectOne {
    open: boolean,
    id?: string | null,
    title: string,
    callback?: () => void
}